package com.cfh.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import aia.cn.integration.nba.dto.premiumCalculation.PremiumPolicy;
import aia.cn.integration.nba.dto.premiumCalculation.PremiumPolicyRequest;
import aia.cn.integration.nba.dto.premiumCalculation.PremiumPolicyResponse;
import aia.cn.integration.nba.service.NBAServiceProxy;

public class Ws02 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public Ws02() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<body>");
		out.println("<head>");
		out.println("<title>Blank Page</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h3>Blank Page</h3>");
		out.println("<pre>Method: " + request.getMethod());
		out.println("Request URI: " + request.getRequestURI());
		out.println("Protocol: " + request.getProtocol());
		out.println("PathInfo: " + request.getPathInfo());
		out.println("Remote Address: " + request.getRemoteAddr());

		out.println("Trace: ");
		try {
			NBAServiceProxy proxy = new NBAServiceProxy();
			out.println("01. init> Current Endpoint is:" + proxy.getEndpoint());
			proxy.setEndpoint("http://localhost:25000/NBSOA/services/NBAService/");
			out.println("02. after change> Current Endpoint is:" + proxy.getEndpoint());
			PremiumPolicyRequest req = new PremiumPolicyRequest();
			PremiumPolicy policy = new PremiumPolicy();
			req.setPolicy(policy);
			PremiumPolicyResponse res = proxy.premiumPolicy(req);
			if (res == null || res.getResult() == null) {
				out.println("it is null of 'proxy.premiumPolicy(req)'");
			} else {
				out.println("getResult().getReturnFlag() = " + res.getResult().getReturnFlag());
				out.println("getResult().getErrorMessage() = " + res.getResult().getErrorMessage());
			}
		} catch (Exception e) {
			e.printStackTrace(out);
		} finally {
			out.println("</pre>");
			out.println("</body>");
			out.println("</html>");

		}

	}

}
